function fsb_plot_voxel_timecourse(sandbox,idat,position)

% FSB - DEV: Show voxel timecourse in detail
%
% EXAMPLE:
% fsb_plot_voxel_timecourse(sandbox,idat,position)
%
% INPUT:
% sandbox: sandbox experiment struct
% idat: 4D image data
% position: coordinates of voxel
%
% OUTPUT:
% Figure with voxel timecourse
%
% CALLED BY:
% fsb_diag.m
%
% NOTES:
% in development
%
% Copyright 2010 MPI for Biological Cybernetics
% Author: Steffen Stoewer
% License:GNU GPL, no express or implied warranties
%
% $ Revision 1.0
%
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

figure(104); set(gcf,'Name','Voxel timecourse');

clf;
lw = 150/ length(sandbox.intrial);
lw =lw*4;
temp = find(sandbox.intrial(:,1) == 1);
temp2 = diff(sandbox.intrial(:,4));
temp3 = find(temp2 == 1);
temp3 = [0; temp3; size(sandbox.intrial,1)];
temp3(temp3==0)=1;
vxtc = squeeze(idat(position(1),position(2),position(3),:));

%~~~~~~~~~~~~~
% Find value range
%~~~~~~~~~~~~~
min_vxtc = min(vxtc);
max_vxtc = max(vxtc);

%~~~~~~~~~~~~~
% Plot figure
%~~~~~~~~~~~~~
hold on;

%~~~~~~~~~~~~~
% Draw trials
%~~~~~~~~~~~~~
line([temp,temp],[min_vxtc,max_vxtc],'LineWidth',lw,'Color',[1 1 0.5]);

%~~~~~~~~~~~~~
% Draw run border
%~~~~~~~~~~~~~
line([[temp3; temp3],[temp3;temp3]],[min_vxtc,max_vxtc],'LineWidth',1,'Color',[0 0 0]);

%~~~~~~~~~~~~~
% Plot voxel time course
%~~~~~~~~~~~~~
plot(vxtc)

%~~~~~~~~~~~~~
% Plot labels
%~~~~~~~~~~~~~
axis tight;
xlabel('Volume');
ylabel('Intensity value');
%Title('Voxel timecourse over volumes');
end

